import importJwt from "jsonwebtoken";

class JsonWebToken {
    secret: string;
    constructor(secret: string) {
        this.secret = secret
    }
    createToken(info: any, time?: Number) {
        if (!time) {
            let token = importJwt.sign(info, this.secret, {
                //Token有效时间 单位s
                expiresIn: 60 * 60 * 10
            })
            return token;
        } else {
            let token = importJwt.sign(info, this.secret, {
                //Token有效时间 单位s
                expiresIn: time
            })
            return token;
        }

    };
    verifyToken(token: string) {
        return new Promise((res, rej) => {
            importJwt.verify(token, this.secret, (error, result) => {
                if (error) {
                    rej(error.name)
                } else {
                    res(result)
                }
            })
        })
    }
}
console.log("importJwt");
const jwt = new JsonWebToken("test");
export default jwt;
